var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, a) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var a in e)
              Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
          })(e, a);
      };
      return function (e, a) {
        function i() {
          this.constructor = e;
        }
        if ("function" != typeof a && null !== a)
          throw new TypeError(
            "Class extends value " + String(a) + " is not a constructor or null"
          );
        t(e, a),
          (e.prototype =
            null === a
              ? Object.create(a)
              : ((i.prototype = a.prototype), new i()));
      };
    })(),
  ChatRoomView = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        (e.chatRegionArr = []),
        (e.chatRectArr = []),
        (e.chatMarketArr = []),
        (e.chatCityArr = []),
        (e.chatTeamArr = []),
        (e.chatLineArr = []),
        (e.chatLimitInt = 0),
        (e.chatMsgTotalHeigh = 0),
        (e.selectedIdx = 0),
        (e.chatface = ChatFaceView.showChatFaceView()),
        e.label_localP.on(Laya.Event.CLICK, e, e.onLookLocalPlayerAction),
        e.onSelectChatRoomFn(e.tab_chatroom.selectedIndex),
        (e.tab_chatroom.selectHandler = new Handler(e, e.onSelectChatRoomFn)),
        (e.tab_chatItem.selectHandler = new Handler(
          e,
          e.onSelectChatItemAction
        )),
        e.image_close_chat.on(Laya.Event.CLICK, e, e.onDidCloseChatAction),
        Laya.stage.on("faceType", e, e.onGetFaceEmojiType),
        Laya.stage.on("ChatRoomView", e, e.eventHandler),
        WebSocketService.addListener({
          caller: e,
          code: 1344,
          method: e.onSaiCaiTongZiDataFn,
        }),
        e.image_face_emoji.on(Laya.Event.CLICK, e, e.onSelectedFaceEmojiAction),
        WebSocketService.addListener(
          { caller: e, code: 260, method: e.chatFromServerMessageFn },
          !0
        ),
        WebSocketService.addListener(
          { caller: e, code: 66, method: e.chatFromServerMessageListFn },
          !0
        ),
        WebSocketService.addListener({
          caller: e,
          code: 100,
          method: e.onLoadLocalPlayerDataFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4210,
          method: e.onLoadMultiMyTeamChatDataFn,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4212,
          method: e.onLoadMyTeamChatDataFn,
        }),
        e
      );
    }
    return (
      __extends(e, t),
      (e.openRoomView = function () {
        return (
          null == this.chatV && (this.chatV = new e()),
          (this.chatV.tab_chatroom.selectedIndex = 0),
          (this.chatV.tab_chatItem.selectedIndex = 0),
          (this.chatV.chatRegionArr = []),
          (this.chatV.chatRectArr = []),
          (this.chatV.chatMarketArr = []),
          (this.chatV.chatCityArr = []),
          (this.chatV.chatLineArr = []),
          (this.chatV.chatTeamArr = []),
          (this.chatV.isUnfold = !1),
          this.chatV.chatPanel.removeChildren(),
          (this.chatV.sancaiObj = {}),
          (this.chatV.sancaiFlag = !1),
          (this.chatV.currentPage = !0),
          (this.chatV.tab_chatroom.visible = !0),
          (this.chatV.tab_chatItem.visible = !1),
          this.chatV
        );
      }),
      (e.prototype.onLookLocalPlayerAction = function () {
        var t = LocalPlayerView.openLocalPlayer();
        t.pos(0, 70), Laya.stage.addChild(t);
      }),
      (e.prototype.onLoadLocalPlayerDataFn = function (t) {
        if (((this.label_localP.text = "玩家(" + t.num + ")"), 0 == t.code)) {
          var e = t.num;
          (parseInt(e) < 0 || void 0 == e) && (e = 0);
        }
      }),
      (e.prototype.initChatUI = function () {
        (this.chatLineArr = this.chatRegionArr),
          (this.chatLimitInt = 30),
          (this.chatMsgTotalHeigh = 0),
          this.initEvent(),
          (this.chatPanel.vScrollBarSkin = "comp/Server/chatPaneScroll.png"),
          (this.chatPanel.vScrollBar.isVertical = !0),
          (this.chatPanel.vScrollBar.elasticBackTime = 600),
          (this.chatPanel.vScrollBar.elasticDistance = 200),
          WebSocketService.send({ c: 66 });
      }),
      (e.prototype.initEvent = function () {
        this.sendMsgBtn.on(Laya.Event.CLICK, this, this.onSendMsgClick);
      }),
      (e.prototype.onSendMsgClick = function () {
        var t = this.onGetChatInfo();
        if (void 0 !== t) {
          var e = this.getType(this.selectedIdx);
          if (1 == this.sancaiFlag)
            NormalDialog.showNormalDialog(
              "您将以散财的形式在世界发言",
              this,
              this.onSanCaiMethod
            );
          else {
            if (10 == e)
              return (
                WebSocketService.send({ c: 4212, d: { msg: t } }),
                void (this.chatMsgTextInput.text = "")
              );
            WebSocketService.send({ c: 260, d: { t: e, c: t } }),
              (this.chatMsgTextInput.text = "");
          }
        }
      }),
      (e.prototype.onSanCaiMethod = function () {
        var t = this.chatMsgTextInput.text;
        WebSocketService.send({
          c: 1344,
          d: { type: this.sancaiObj.data, msg: t },
        }),
          (this.sancaiObj = {}),
          (this.sancaiFlag = !1),
          (this.sancaiBtn.label = "选择金额"),
          (this.chatMsgTextInput.text = "");
      }),
      (e.prototype.onGetChatInfo = function () {
        var t = this.chatMsgTextInput.text;
        if ("" != t) return t;
      }),
      (e.prototype.onReChatLinePos = function () {
        this.chatMsgTotalHeigh = 0;
        for (var t, e = 0; e < this.chatLineArr.length; e++)
          ((t = this.chatLineArr[e]).y = this.chatMsgTotalHeigh),
            (this.chatMsgTotalHeigh += t.height);
      }),
      (e.prototype.onDidChatLineFn = function (t) {
        void 0 != t.target.tag &&
          1e3 != t.target.tag &&
          FriendsDetailDialog.showFriendDialog(t.target.tag, !0);
      }),
      (e.prototype.onSelectChatRoomFn = function (t) {
        for (var e = 0; e < this.tab_chatroom._childs.length; e++) {
          (this.tab_chatroom._childs[e].height = 28),
            (this.tab_chatroom._childs[e].y = 0);
          this.tab_chatroom._childs[e];
          e == t
            ? ((this.tab_chatroom._childs[e].y = -1),
              (this.tab_chatroom._childs[e].height = 29))
            : ((this.tab_chatroom._childs[e].y = 0),
              (this.tab_chatroom._childs[e].height = 28));
        }
        if (
          ((this.selectedIdx = t),
          (this.moneyAreaV = MoneyAreaView.showMoneyView(
            this,
            this.onDidSendSanCaiAction
          )),
          MoneyAreaView.removeMoneyAreaView(),
          (this.sancaiObj = null),
          (this.chatMsgTextInput.text = ""),
          0 == t)
        )
          this.chatLineArr = this.chatRegionArr;
        else if (1 == t) this.chatLineArr = this.chatRectArr;
        else if (2 == t) this.chatLineArr = this.chatMarketArr;
        else if (3 == t)
          (this.chatLineArr = this.chatCityArr),
            this.moneyAreaV.pos(220, 465),
            Laya.stage.addChild(this.moneyAreaV);
        else if (4 == t)
          return void WebSocketService.send({ c: 4210, d: { pageNum: 0 } });
        this.updateChatLineView();
      }),
      (e.prototype.onSelectChatItemAction = function (t) {
        for (var e = 0; e < this.tab_chatItem._childs.length; e++) {
          (this.tab_chatItem._childs[e].height = 28),
            (this.tab_chatItem._childs[e].y = 0);
          this.tab_chatItem._childs[e];
          e == t
            ? ((this.tab_chatItem._childs[e].y = -1),
              (this.tab_chatItem._childs[e].height = 29))
            : ((this.tab_chatItem._childs[e].y = 0),
              (this.tab_chatItem._childs[e].height = 28));
        }
        (this.selectedIdx = t),
          (this.moneyAreaV = MoneyAreaView.showMoneyView(
            this,
            this.onDidSendSanCaiAction
          )),
          MoneyAreaView.removeMoneyAreaView(),
          (this.sancaiObj = null),
          (this.chatMsgTextInput.text = ""),
          0 == t
            ? (this.chatLineArr = this.chatRegionArr)
            : 1 == t
            ? (this.chatLineArr = this.chatRectArr)
            : 2 == t
            ? (this.chatLineArr = this.chatMarketArr)
            : 3 == t
            ? ((this.chatLineArr = this.chatCityArr),
              this.moneyAreaV.pos(220, 450),
              Laya.stage.addChild(this.moneyAreaV))
            : 4 == t &&
              (WebSocketService.send({ c: 4210, d: { pageNum: 0 } }),
              (this.chatLineArr = this.chatTeamArr)),
          this.updateChatLineView();
      }),
      (e.prototype.onDidSendSanCaiAction = function (t) {
        this.sancaiBtn = t.btn_moneyArea;
      }),
      (e.prototype.chatFromServerMessageFn = function (t) {
        0 == t.code
          ? (6 === t.data.t &&
              (Global.isShowMarquee
                ? setTimeout(function () {
                    var e = MarqueeView.showMarqueeView(t.data.c);
                    e.pos(17, 85), Laya.stage.addChild(e);
                  }, 3e3)
                : Utils.countDownTriggerEvent() &&
                  setTimeout(function () {
                    var e = MarqueeView.showMarqueeView(t.data.c);
                    e.pos(17, 85), Laya.stage.addChild(e);
                  }, 3e3)),
            this.chatFromServerMessageInit(t.data))
          : ToastView.toastView(t.msg);
      }),
      (e.prototype.chatFromServerMessageListFn = function (t) {
        if (0 == t.code)
          for (var e = t.data.length - 1; e >= 0; e--)
            this.chatFromServerMessageInit(t.data[e]);
        else ToastView.toastView(t.msg);
      }),
      (e.prototype.onLoadMultiMyTeamChatDataFn = function (t) {
        if (0 == t.code)
          for (var e = t.data.length - 1; e >= 0; e--)
            this.onLoadMyTeamChatDataFn(t.data[e]);
      }),
      (e.prototype.chatFromServerMessageInit = function (t) {
        if (null != t) {
          var e = this.getChatLineArr(t.t);
          if (null != e) {
            var a = new ChatLineView();
            if (
              ((a.textfield.tag = t.rid),
              a.otherChatLineMessage(t),
              a.on(Laya.Event.CLICK, this, this.onDidChatLineFn),
              e.push(a),
              e == this.chatLineArr &&
                (this.chatPanel.addChild(a),
                (a.y = this.chatMsgTotalHeigh),
                (this.chatMsgTotalHeigh += a.height),
                (this.chatPanel.vScrollBar.max = this.chatPanel.contentHeight),
                (this.chatPanel.vScrollBar.value =
                  this.chatPanel.vScrollBar.max)),
              e.length > 30)
            ) {
              e.shift().removeSelf();
            }
          }
        }
      }),
      (e.prototype.updateChatLineView = function () {
        this.chatPanel.removeChildren(), (this.chatMsgTotalHeigh = 0);
        for (var t, e = 0, a = this.chatLineArr.length; e < a; e++)
          ((t = this.chatLineArr[e]).y = this.chatMsgTotalHeigh),
            (this.chatMsgTotalHeigh += t.height),
            this.chatPanel.addChild(t);
        (this.chatPanel.vScrollBar.max = this.chatPanel.contentHeight),
          (this.chatPanel.vScrollBar.value = this.chatPanel.vScrollBar.max);
      }),
      (e.prototype.getChatLineArr = function (t) {
        return 1 == t
          ? this.chatRegionArr
          : 4 == t
          ? this.chatRectArr
          : 5 == t
          ? this.chatMarketArr
          : 6 == t
          ? this.chatCityArr
          : 10 == t
          ? this.chatTeamArr
          : null;
      }),
      (e.prototype.getType = function (t) {
        return 0 == t
          ? 1
          : 1 == t
          ? 4
          : 2 == t
          ? 5
          : 3 == t
          ? 6
          : 4 == t
          ? 10
          : -1;
      }),
      (e.prototype.onSelectedFaceEmojiAction = function () {
        ChatFaceDialog.showChatFaceView("chatroom");
      }),
      (e.prototype.onGetFaceEmojiType = function (t) {
        var e = t.text;
        this.chatMsgTextInput.text += e;
      }),
      (e.prototype.eventHandler = function (t) {
        "list_money_value" == t.name
          ? ((this.sancaiObj = t), (this.sancaiFlag = !0))
          : "group_team" == t.name &&
            (t.data
              ? ((this.tab_chatroom.visible = !1),
                (this.tab_chatItem.visible = !0),
                (this.tab_chatItem.selectedIndex = 4))
              : ((this.tab_chatroom.visible = !0),
                (this.tab_chatItem.visible = !1)));
      }),
      (e.prototype.onSaiCaiTongZiDataFn = function (t) {
        ToastView.toastView(t.msg);
      }),
      (e.prototype.onLoadMyTeamChatDataFn = function (t) {
        if (0 == t.code) {
          if (
            ((this.tab_chatroom.visible = !1),
            (this.tab_chatItem.visible = !0),
            void 0 == t.data)
          )
            return;
          if (t.data && t.data.length <= 0)
            return (this.chatLineArr = []), void this.updateChatLineView();
          var e = {},
            a = t.data;
          return (
            (e = {
              c: a.msg,
              h: a.date,
              id: a.roleId,
              n: a.userName,
              rid: a.rid,
              t: 10,
            }),
            this.chatTeamArr.push(e),
            (this.chatLineArr = this.chatTeamArr),
            void this.chatFromServerMessageInit(e)
          );
        }
        this.updateChatLineView(),
          (this.tab_chatroom.visible = !0),
          (this.tab_chatItem.visible = !1);
      }),
      (e.prototype.onLoadMyGroupTeamListFn = function (t) {}),
      (e.prototype.onDidCloseChatAction = function (t) {
        console.log("点击切换弹窗 ： " + this.isUnfold);
        var e = 0.2 * Browser.clientHeight,
          a = 0.6 * Browser.clientHeight;
        (this.isUnfold = !this.isUnfold),
          this.isUnfold
            ? ((this.y = e),
              (this.height = a),
              (this.lab_chat_content_view.height = a),
              (this.image_chat_content.height = a),
              (this.image_close_chat.rotation = 180))
            : ((this.y = 460),
              (this.height = 160),
              (this.lab_chat_content_view.height = 160),
              (this.image_chat_content.height = 160),
              (this.image_close_chat.rotation = 0));
      }),
      e
    );
  })(ui.ChatRoomViewUI);
